package com.cictec.middleware.distribute.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cictec.middleware.commons.utils.Result;
import com.cictec.middleware.commons.utils.ResultUtil;
import com.cictec.middleware.core.entity.Device;
import com.cictec.middleware.distribute.service.RedisService;

/**
 * 中间件对外业务处理接口【设备登录、退出、鉴权业务】
 * 
 * @author Administrator
 *
 */
@RestController
public class MiddlewareDeviceController {

	private static Logger logger = LoggerFactory.getLogger(MiddlewareDeviceController.class);
	
	@Autowired
	private RedisService redisService;

	@RequestMapping(value = "/distribute/deviceConnectByDevcode")
	public Result deviceConnectByDevcode(@RequestParam("devCode") String devCode) {

		System.out.println("这里目前不做操作，待有业务时候添加");
		// 这里目前不做操作，待有业务时候添加
		return ResultUtil.getSuccessResult("设备登录成功");
	}

	@RequestMapping(value = "/distribute/deviceDisConnect")
	public Result deviceDisConnect(@RequestParam("devCode") String devCode) {
		// 这里目前不做操作，待有业务时候添加
		System.out.println("这里目前不做操作，待有业务时候添加");
		return ResultUtil.getSuccessResult("设备退出成功");
	}

	/**
	 * 设备连接，通过设备号或者设备序列号
	 * 
	 * @param serialNumber
	 * @return data JSONObject
	 */
	@RequestMapping(value = "/distribute/getDeviceBySerialNumber")
	public Device getDeviceBySerialNumber(@RequestParam("serialNumber") String serialNumber) {
		
		return redisService.getDeviceBySerialNumber(serialNumber);
	}

	/**
	 * 设备连接，通过设备号或者设备序列号
	 * 
	 * @param devCode
	 * @return data JSONObject
	 */
	@RequestMapping(value = "/distribute/getDeviceByDevCode")
	public Device getDeviceByDevCode(@RequestParam("serialNumber") String devCode) {
		return redisService.getDeviceByDevCode(devCode);
	}
	
	@RequestMapping(value = "/distribute/updateDeviceSerialNumber")
	public Result updateDeviceSerialNumber(@RequestParam("devCode") String devCode,
			@RequestParam("serialNumber") String serialNumber) {
		
		logger.error("更新设备序列号");
		return null;
	}

}
